package com.jhx.mall.dao.impl;

import com.jhx.mall.dao.BaseDao;
import com.jhx.mall.dao.DtsArticleDao;
import com.jhx.mall.entity.DtsArticle;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class DtsArticleDaoImpl extends BaseDao implements DtsArticleDao {
    @Override
    public List<DtsArticle> selectAll() {
        List<DtsArticle> list = new ArrayList<>();
        String sql = "select id, type, title, content, add_time, update_time, deleted from dts_article where deleted = 0";
        rs = executeQuery(sql);
        try {
            while (rs.next()) {
                DtsArticle dtsArticle = new DtsArticle();
                dtsArticle.setId(rs.getLong("id"));
                dtsArticle.setType(rs.getString("type"));
                dtsArticle.setTitle(rs.getString("title"));
                dtsArticle.setContent(rs.getString("content"));
                dtsArticle.setAddTime(rs.getString("add_time"));
                dtsArticle.setUpdateTime(rs.getString("update_time"));
                dtsArticle.setDeleted(rs.getLong("deleted"));
                list.add(dtsArticle);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            super.closeAll(rs, pstmt, conn);
        }
        return list;
    }
}
